﻿using ff14bot;
using ff14bot.Enums;
using MoreDots.SpellNames.Classes;
using MoreDots.SpellNames.Jobs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoreDots.Rotations.Classes
{
    public class Pugilist : MoreDots
    {
        public override string Name { get { return "MoreDots [" + GetType().Name + "]"; } }
        public override ClassJobType[] Class { get { return new ClassJobType[] { ClassJobType.Pugilist }; } }

        #region Lower LvL Rotations
        public async override Task<bool> CombatLvL1()
        {
            if (await Foresight()) return true;
            if (await Cure()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL2() { return await CombatLvL1(); }
        public async override Task<bool> CombatLvL4()
        {
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await VenomousBite()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL6() { return await CombatLvL4(); }
        public async override Task<bool> CombatLvL8()
        {
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await VenomousBite()) return true;
            if (await RaptorForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL10() { return await CombatLvL8(); }
        public async override Task<bool> CombatLvL12()
        {
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL14() { return await CombatLvL12(); }
        public async override Task<bool> CombatLvL16()
        {
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await RaptorForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL18()
        {
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL20() { return await CombatLvL18(); }
        public async override Task<bool> CombatLvL22()
        {
            if (await FistsOfEarth()) return true;
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL24() { return await CombatLvL22(); }
        public async override Task<bool> CombatLvL26() { return await CombatLvL22(); }
        public async override Task<bool> CombatLvL28() { return await CombatLvL22(); }
        public async override Task<bool> CombatLvL30()
        {
            if (await FistsOfEarth()) return true;
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await PugilistSpells.CrossClass.MercyStroke.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await CoeurlForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL32() { return await CombatLvL30(); }
        public async override Task<bool> CombatLvL34() { return await CombatLvL30(); }
        public async override Task<bool> CombatLvL36() { return await CombatLvL30(); }
        public async override Task<bool> CombatLvL38()
        {
            if (await FistsOfEarth()) return true;
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.CrossClass.BloodForBlood.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await PugilistSpells.CrossClass.MercyStroke.Cast()) return true;
            if (await PugilistSpells.SteelPeak.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await CoeurlForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL40() { return await CombatLvL38(); }
        public async override Task<bool> CombatLvL42()
        {
            if (await FistsOfEarth()) return true;
            if (await Mantra()) return true;
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.CrossClass.BloodForBlood.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await PugilistSpells.CrossClass.MercyStroke.Cast()) return true;
            if (await PugilistSpells.SteelPeak.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await CoeurlForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL44() { return await CombatLvL42(); }
        public async override Task<bool> CombatLvL46()
        {
            if (await FistsOfEarth()) return true;
            if (await Mantra()) return true;
            if (await Featherfoot()) return true;
            if (await Foresight()) return true;
            if (await KeenFlurry()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.CrossClass.BloodForBlood.Buff()) return true;
            if (await PugilistSpells.InternalRelease.Buff()) return true;
            if (await PugilistSpells.Haymaker.Cast()) return true;
            if (await PugilistSpells.CrossClass.MercyStroke.Cast()) return true;
            if (await PugilistSpells.SteelPeak.Cast()) return true;
            if (await PugilistSpells.HowlingFist.Cast()) return true;
            if (await Virus()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await CoeurlForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }
        public async override Task<bool> CombatLvL48() { return await CombatLvL46(); }
        #endregion

        public async override Task<bool> CombatLvL50()
        {
            if (await FistsOfEarth()) return true;
            if (await SecondWind()) return true;
            if (await Featherfoot()) return true;
            if (await KeenFlurry()) return true;
            if (await Foresight()) return true;
            if (await Convalescence()) return true;
            if (await Cure()) return true;
            if (await Physick()) return true;
            if (await TouchOfDeath()) return true;
            if (await PerfectBalance()) return true;
            if (await PugilistSpells.CrossClass.BloodForBlood.Buff()) return true;
            if (await PugilistSpells.CrossClass.Bloodbath.Buff()) return true;
            if (await PugilistSpells.CrossClass.RagingStrikes.Buff()) return true;
            if (await MonkSpells.InternalRelease.Buff()) return true;
            if (await MonkSpells.Haymaker.Cast()) return true;
            if (await Virus()) return true;
            if (await MonkSpells.CrossClass.MercyStroke.Cast()) return true;
            if (await MonkSpells.SteelPeak.Cast()) return true;
            if (await MonkSpells.HowlingFist.Cast()) return true;
            if (await VenomousBite()) return true;
            if (await Fracture()) return true;
            if (await RaptorForm()) return true;
            if (await CoeurlForm()) return true;
            if (await BootshineCombo()) return true;

            return true;
        }

        #region Cross-Class Abilities
        private async Task<bool> Cure()
        {
            if (Core.Player.CurrentHealthPercent < 40)
                return await PugilistSpells.CrossClass.Cure.Cast(Core.Player);

            return false;
        }
        private async Task<bool> Physick()
        {
            if (Core.Player.CurrentHealthPercent < 40)
                return await PugilistSpells.CrossClass.Physick.Cast(Core.Player);

            return false;
        }
        private async Task<bool> Virus()
        {
            if (!Core.Player.CurrentTarget.HasAura(PugilistSpells.CrossClass.Virus.Name))
                return await PugilistSpells.CrossClass.Virus.Cast();

            return false;
        }
        private async Task<bool> Fracture()
        {
            if (!Core.Player.CurrentTarget.HasAura(PugilistSpells.CrossClass.Fracture.Name))
                return await PugilistSpells.CrossClass.Fracture.Cast();

            return false;
        }
        private async Task<bool> Foresight()
        {
            if (Core.Player.CurrentHealthPercent < 60)
                return await PugilistSpells.CrossClass.Foresight.Buff();

            return false;
        }
        private async Task<bool> MercyStroke()
        {
            return await PugilistSpells.CrossClass.MercyStroke.Cast();
        }
        private async Task<bool> Invigorate()
        {
            if (Core.Player.CurrentTPPercent < 50)
                return await PugilistSpells.CrossClass.Invigorate.Buff();

            return false;
        }
        private async Task<bool> KeenFlurry()
        {
            if (Core.Player.CurrentHealthPercent < 80)
                return await PugilistSpells.CrossClass.KeenFlurry.Buff();

            return false;
        }
        private async Task<bool> Convalescence()
        {
            if (Core.Player.CurrentHealthPercent < 70)
                return await PugilistSpells.CrossClass.Convalescence.Buff();

            return false;
        }
        private async Task<bool> VenomousBite()
        {
            if (!Core.Player.CurrentTarget.HasAura(PugilistSpells.CrossClass.VenomousBite.Name, true, 3000))
                return await PugilistSpells.CrossClass.VenomousBite.Cast();

            return false;
        }
        #endregion
        #region Combat Abilities
        #region Stances
        private async Task<bool> OpoOpoForm()
        {
            if (!Core.Player.HasAura("Opo-Opo Form"))
                return false;

            return await PugilistSpells.Bootshine.Cast();
        }
        private async Task<bool> RaptorForm()
        {
            if (!Core.Player.HasAura("Raptor Form"))
                return false;

            if (!Core.Player.HasAura(PugilistSpells.TwinSnakes.Name, true, 5000) || Core.Player.CurrentTarget.IsBehind)
                return await PugilistSpells.TwinSnakes.Cast();

            return await PugilistSpells.TrueStrike.Cast();
        }
        private async Task<bool> CoeurlForm()
        {
            if (!Core.Player.HasAura("Coeurl Form"))
                return false;

            if (!Core.Player.HasAura(PugilistSpells.Demolish.Name, true, 6000))
                return await PugilistSpells.Demolish.Cast();

            if (Core.Player.CurrentTarget.IsFlanking)
                return await PugilistSpells.SnapPunch.Cast();

            return await PugilistSpells.Demolish.Cast();
        }
        #endregion
        #region Combos
        private async Task<bool> BootshineCombo()
        {
            if (Core.Player.HasAura("Coeurl Form"))
                return await PugilistSpells.SnapPunch.Cast();

            if (Core.Player.HasAura("Raptor Form"))
                return await PugilistSpells.TrueStrike.Cast();

            return await PugilistSpells.Bootshine.Cast();
        }
        #endregion
        #region Abilities
        private async Task<bool> FistsOfEarth()
        {
            if (!Core.Player.HasAura(PugilistSpells.FistsOfEarth.Name) && (Core.Player.CurrentHealth < 30) || Core.Player.ClassLevel < 40)
                return await PugilistSpells.FistsOfEarth.Cast(Core.Player);

            return false;
        }
        private async Task<bool> TouchOfDeath()
        {
            if (!Core.Player.CurrentTarget.HasAura(PugilistSpells.TouchOfDeath.Name, true, 3000))
                return await PugilistSpells.TouchOfDeath.Cast();

            return false;
        }
        private async Task<bool> PerfectBalance()
        {
            if (!Core.Player.HasAura(PugilistSpells.PerfectBalance.Name))
                return await PugilistSpells.PerfectBalance.Cast(Core.Player);

            if (Core.Player.HasAura(PugilistSpells.PerfectBalance.Name))
            {
                if (!Core.Player.CurrentTarget.HasAura(PugilistSpells.Demolish.Name))
                    return await PugilistSpells.Demolish.Cast();

                if (!Core.Player.HasAura(PugilistSpells.TwinSnakes.Name))
                    return await PugilistSpells.TwinSnakes.Cast();

                return await PugilistSpells.SnapPunch.Cast();
            }

            return false;
        }
        #endregion
        #region Defensive
        private async Task<bool> SecondWind()
        {
            if (Core.Player.CurrentHealthPercent < 50)
                return await PugilistSpells.SecondWind.Buff();

            return false;
        }
        private async Task<bool> Mantra()
        {
            return false;
        }
        private async Task<bool> Featherfoot()
        {
            if (Core.Player.CurrentHealthPercent < 60 && Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) < 5)
                return await PugilistSpells.Featherfoot.Buff();

            return false;
        }
        #endregion
        #endregion
    }
}
